// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/daguan/api/DaguanProgramApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/daguan/model/DaguanProgramReq'
import BaseClass from '@api/daguan/model/DaguanProgramDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'dto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 基础 —————————————————————————————— //

  async getBase(baseParam, TIP = '查询基础') {
    const DTO = CORE.grpcDTO({}, baseParam)
    await CORE.grpc(TIP, CLIENT, 'refresh', DTO).catch(() => null)
    return {}
  },

  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'daguanProgramQuery', DTO)
    return [resp.comQuery.totalCount, resp.dto || []]
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async submit(one, TIP = '提交') {
    const DTO = CORE.grpcDTO({}, one)
    await CORE.grpc(TIP, CLIENT, 'refresh', DTO)
    return CORE.grpcOK(TIP)
  },
}
